//
//  MeCommunityViewController.m
//  DBAChain
//
//  Created by Mxionlly on 2018/9/8.
//  Copyright © 2018年 Evan. All rights reserved.
//

#import "MeCommunityViewController.h"
#import "MeCommunityHeadView.h"
#import "MeCommunityViewCell.h"
#import "taskUserManagerService.h"
#import <Masonry.h>
#import "dataCommunityList.h"

@interface MeCommunityViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong)UITableView    *tableView;
@property (nonatomic,strong)MeCommunityHeadView *headView;
@property (nonatomic,strong) dataCommunityInfo * dataInfo;

@end

@implementation MeCommunityViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"我的社区";
    
    [self tableView];
    [self loadData];
}

-(void)loadData{
    [DKProgressHUD showLoading];
    [taskUserManagerService getUserCommunityInfo:nil success:^(dataCommunity *response, BOOL success) {
        [DKProgressHUD dismiss];
        if (success) {
            self.dataInfo = response.data;
            self.headView.lbdayProfit.text = [NSString stringWithFormat:@"%.2f",self.dataInfo.ShareNumberToday];
            self.headView.lbtotalProfit.text = [NSString stringWithFormat:@"%.2f",self.dataInfo.ShareNumber];
            //
            self.headView.lbmemberNumber.text = [NSString stringWithFormat:@"%ld",self.dataInfo.InvCount];
            
            [self.tableView reloadData];
            return ;
        }
        [DKProgressHUD showErrorWithStatus:response.message];
    } failture:^(NSError *error, NSString *strDescription) {
        [DKProgressHUD dismiss];
        [DKProgressHUD showErrorWithStatus:strDescription];
    }];
}


-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    [self setBlackStatus:YES];
    
    self.hidesBottomBarWhenPushed = NO;
    self.tabBarController.tabBar.hidden = YES;
    self.navigationController.navigationBar.hidden = NO;
}

#pragma mark - init
-(UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc]init];
        [self.view addSubview:_tableView];
        [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.and.right.mas_equalTo(self.view);
            make.bottom.mas_equalTo(self.view.mas_bottom).offset(0);
            make.top.mas_equalTo(self.view).offset(150);
        }];
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.backgroundColor  = [UIColor clearColor];
        _tableView.scrollEnabled = YES;
        _tableView.estimatedSectionFooterHeight = 0;
        _tableView.estimatedSectionHeaderHeight = 0;
    }
    return _tableView;
}

-(MeCommunityHeadView *)headView
{
    if (!_headView) {
        _headView = [MeCommunityHeadView getHeadView];
    }
    return _headView;
}

#pragma mark - UITableView
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 2;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.00001;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 240;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    return self.headView;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50.0;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    MeCommunityViewCell *cell = [MeCommunityViewCell cellWithTableView:tableView];
    if(indexPath.row == 0){
        cell.labelLevel.text = [NSString stringWithFormat:@"1级"];
        cell.labelPerson.text = [NSString stringWithFormat:@"%ld人",(long)self.dataInfo.InvCountNo1];
    }else{
        cell.labelLevel.text = [NSString stringWithFormat:@"2级"];
        cell.labelPerson.text = [NSString stringWithFormat:@"%ld人",(long)self.dataInfo.InvCountNo2];
    }
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    //    [self.navigationController pushViewController:vc animated:YES];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
